<template>
    <!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh"> -->
        <!-- 表格 -->
        <div class="DataManagement">
            <div class="main_topWarp">
                <div class="DataManagement_back" >
                    <span class="DataManagement_title">数据</span>
                    </div>
            </div>
            <div class="DataManagement_main">
                <div>
                    <van-collapse v-model="activeNames">
                        <van-cell-group>
                            <van-collapse-item title="数据填报" name="1" class="datatitle_style">
                                <van-cell v-if="dataReporting.length>0" @click="toReportingPage(item.ID,1,item.ShareName)" class="datamain_style" v-for="item in dataReporting" :key="item.ID" :title="item.ShareName"  is-link />
                                <van-cell v-else>暂无数据</van-cell>
                            </van-collapse-item>
                        </van-cell-group>
                    </van-collapse>

                    <van-collapse v-model="activeNames">
                        <van-cell-group>
                            <van-collapse-item title="数据管理" name="2"  class="datatitle_style">
                                <van-cell v-if="dataManagement.length>0" @click="toReportingPage(item.ID,2,item.ShareName)" class="datamain_style" v-for="item in dataManagement" :key="item.ID" :title="item.ShareName"  is-link />
                                    <van-cell v-else>暂无数据</van-cell>
                            </van-collapse-item>
                        </van-cell-group>
                    </van-collapse>
                </div>

            </div>
        </div>
    <!-- </van-pull-refresh> -->
</template>

<script>
import { onMounted, reactive, ref, toRefs } from 'vue'
import { Toast, Notify} from 'vant';
import { useStore } from "vuex"; // ⚪️ 引入状态管理
import router from "@/router";
import { ShareInfoGetMainList } from "@/network/DataManagement.js";
export default {
    setup() {
        const state = reactive({
            isLoading: false,
            // =====
            list: [],
            dataReporting:[],
            dataManagement:[],
            loading: false,
            finished: false,
            activeNames: ['1','2']
        })
        onMounted(() => {
            getInitDataList()
        });
        // 获取首页填报页列表数据
        const getInitDataList=()=>{
            state.loading = true;
            ShareInfoGetMainList().then((res)=>{
                console.log('res',res);
                state.list=res.data
                state.dataReporting = res.data.filter(item => item.ShareSort === "数据填报");
                state.dataManagement = res.data.filter(item => item.ShareSort === "数据管理");

            })
        } 
        // 下拉刷新
        const onRefresh = () => {
            getInitDataList()
            state.isLoading = false
        }

        const toReportingPage=(Id, type,shareName)=>{
            if (type=='1') {
                router.push({
                    name: 'DataReporting', // 假定dateReporting是你的路由名称
                    query: { // 传递参数到dateReporting页面
                        Id: Id,
                        type: type,
                        shareName:shareName
                    }
                });
            }else if(type=='2'){
                router.push({
                    name: 'DataManaging', // 假定dateReporting是你的路由名称
                    query: { // 传递参数到dateReporting页面
                        Id: Id,
                        type: type,
                        shareName:shareName
                    }
                });
            }
        }
        return {
            ...toRefs(state),
            onRefresh,
            toReportingPage
        };
    },
};
</script>

<style scoped></style>